home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / WINER.ZIP / CHAP10-3.BAS < prev    next >
BASIC Source File  |  1992-05-13  |  2KB  |  71 lines

  1. '********** CHAP10-3.BAS - demonstrates direct speaker control via OUT
  2.  
  3. 'Copyright (c) 1992 Ethan Winer
  4.  
  5. DEFINT A-Z
  6. DECLARE SUB BSound (Frequency, Duration)
  7.  
  8. CLS
  9.  
  10. PRINT "Sweep sound"
  11. FOR X = 1 TO 10
  12.   READ Frequency
  13.   CALL BSound(Frequency, 1)
  14. NEXT
  15. DATA 100, 200, 300, 400, 600, 900, 1200, 1500, 1800, 2100
  16.  
  17. PRINT "Press a key for more..."
  18. WHILE INKEY$ = "": WEND
  19.  
  20. PRINT "Telephone"
  21. FOR X = 1 TO 10
  22.   CALL BSound(600, 1)
  23.   CALL BSound(800, 1)
  24. NEXT
  25.  
  26. PRINT "Press a key for more..."
  27. WHILE INKEY$ = "": WEND
  28.  
  29. PRINT "Siren"
  30. FOR X = 1 TO 2
  31.   FOR Y = 600 TO 1000 STEP 15
  32.     CALL BSound(Y, -1)          'negative values leave
  33.   NEXT                          '  the speaker turned on
  34.   FOR Y = 1000 TO 600 STEP -15
  35.     CALL BSound(Y, -1)
  36.   NEXT
  37. NEXT
  38. CALL BSound(600, 1)             'force the speaker off
  39.  
  40. SUB BSound (Frequency, Duration) STATIC
  41.  
  42.   IF Frequency < 33 THEN EXIT SUB
  43.  
  44.   IF NOT BeenHere THEN          'do this only once for a
  45.     BeenHere = -1               '  smoother sound effect
  46.     OUT &H43, 182               'initialize speaker port
  47.   END IF
  48.  
  49.   Period = 1193180 \ Frequency  'convert to period
  50.   OUT &H42, Period AND &HFF     'send it as two bytes
  51.   OUT &H42, Period \ 256        '  in succession
  52.  
  53.   Speaker = INP(&H61)           'read Timer port B
  54.   Speaker = Speaker OR 3        'set the speaker bits on
  55.   OUT &H61, Speaker
  56.  
  57.   DEF SEG = 0
  58.   FOR X = 1 TO ABS(Duration)    'for each tick specified
  59.     ThisTime = PEEK(&H46C)      '  count changes again
  60.     DO                          'wait until the timer
  61.     LOOP WHILE ThisTime = PEEK(&H46C)
  62.   NEXT
  63.  
  64.   IF Duration > 0 THEN          'turn off if requested
  65.     Speaker = INP(&H61)         'read Timer port B
  66.     Speaker = Speaker AND &HFC  'set the speaker bits off
  67.     OUT &H61, Speaker
  68.   END IF
  69.   
  70. END SUB
  71.